package cn.uce.cc.srv.utils;

import cn.uce.base.PubApiObjectConstants;
import cn.uce.base.ccos.LineVo;
import cn.uce.base.ccos.OrderPostParamsVo;
import cn.uce.base.ccos.OrderVo;
import cn.uce.base.vo.*;
import cn.uce.common.omg.cache.FspDictDateCache;
import cn.uce.common.omg.dao.impl.ICsFspDictDateDao;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

//import java.security.NoSuchAlgorithmException;
//import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.*;

@Component
public class HttpClientPubApiUtils {

    private static String asskey;
    private static String comcode;
    private static String seckey;
    private static String version;

    @Value("${ccos.asskey}")
    public  void setAsskey(String asskey) {
        this.asskey = asskey;
    }
    @Value("${ccos.comcode}")
    public  void setComcode(String comcode) {
        this.comcode = comcode;
    }
    @Value("${ccos.seckey}")
    public  void setSeckey(String seckey) {
        this.seckey = seckey;
    }
    @Value("${ccos.version}")
    public  void setVersion(String version) {
        this.version = version;
    }

    public static String buildUpStructure(String interfaceConstants, Map map) {
        String json_object ="";
        if(PubApiObjectConstants.SMS_POST_BY_PHONE_CONTENT.equals(interfaceConstants)) {
            MsgCRMParam msgCRMParam = new MsgCRMParam();
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("content", map.get("content"));
            map_sort.put("mobile", map.get("mobile"));
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObject(msgCRMParam, messageBody, digest, map);
        }else if(PubApiObjectConstants.WAYBILL_SIGN_QUERY_BY_WAYBILL_NO.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("wayBillNo", map.get("wayBillNo").toString());
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.WAYBILL_SIGN_QUERY_BY_WAYBILL_NO, messageBody, digest, map);
        }
        if(PubApiObjectConstants.ORDER_QUERY_BY_PARAM.equals(interfaceConstants)){//query order by phone
            OrderQueryParam orderQueryParam = new OrderQueryParam();
            JSONObject object = new JSONObject();
            String messageBody = SecurityUtils.md5(object.toString(), null);
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.ORDER_QUERY_BY_PARAM, messageBody, digest, map);
        }else if(PubApiObjectConstants.ORDER_POST_FROM_ONLINE.equals(interfaceConstants)) {//post order to order system
            OrderPostParamsVo orderPostParamsVo = new OrderPostParamsVo();
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("orderSource", map.get("orderSource").toString());
            map_sort.put("orderVo", (OrderVo)map.get("orderVo"));
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest = generateDigest(messageBody);
            json_object = convoterObject(orderPostParamsVo, messageBody, digest, map);
        }else if(PubApiObjectConstants.CUSTOMER_QUERY.equals(interfaceConstants)) {//query cusinfo from cusinfo
            CustomerQueryVo customerQueryVo = new CustomerQueryVo();
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("phoneNumber", map.get("phoneNumber").toString());
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObject(customerQueryVo, messageBody, digest, map_sort);
        }else if(PubApiObjectConstants.USER_QUERY.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("userCode", map.get("userCode").toString());
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.USER_QUERY, messageBody, digest, map);
        }else if(PubApiObjectConstants.WAYBILL_QUERY_BY_PHONE_NO.equals(interfaceConstants)) {//query wayBill
            WaybillParam waybillParam = new WaybillParam();
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("phone", map.get("phone").toString());
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObject(waybillParam, messageBody, digest, map);
        }else if(PubApiObjectConstants.WAYBILL_QUERY_BY_WAYBILL_NO.equals(interfaceConstants)) {//query waybill by waybill no
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("wayBillNo", map.get("wayBillNo").toString());
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.WAYBILL_QUERY_BY_WAYBILL_NO, messageBody, digest, map);
        }else if(PubApiObjectConstants.WAYBILL_SIGN_QUERY_BY_WAYBILL_NO.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("wayBillNo", map.get("wayBillNo").toString());
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.WAYBILL_SIGN_QUERY_BY_WAYBILL_NO, messageBody, digest, map);
        }else if(PubApiObjectConstants.ROUTE_QUERY_BY_WAYBILL_NO.equals(interfaceConstants)) {//query waybill route by waybill no
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("wayBillNo", map.get("wayBillNo").toString());
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.ROUTE_QUERY_BY_WAYBILL_NO, messageBody, digest, map);
        }else if(PubApiObjectConstants.WAYBILL_CHANGE_QUERY_BY_WAYBILL_NO.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("waybillNoArray", new Long[] {Long.valueOf(map.get("waybillNoArray").toString())} );
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.WAYBILL_CHANGE_QUERY_BY_WAYBILL_NO, messageBody, digest, map_sort);
        }else if(PubApiObjectConstants.NETWORK_QUERY.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("deptCode", map.get("deptCode"));
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.NETWORK_QUERY, messageBody, digest, map_sort);
        }else if(PubApiObjectConstants.WAYBILL_RECORD_QUERY_BY_WAYBILL_NO.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("wayBillNo", map.get("wayBillNo").toString());
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.WAYBILL_RECORD_QUERY_BY_WAYBILL_NO, messageBody, digest, map);
        }else if(PubApiObjectConstants.ROUTE_TIME_QUERY_BY_WAYBILL_NO.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("sourceZoneCode", String.valueOf(map.get("sourceZoneCode")));
            map_sort.put("productCode", String.valueOf(map.get("productCode")));
            map_sort.put("destZoneCode", String.valueOf(map.get("destZoneCode")));
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.ROUTE_TIME_QUERY_BY_WAYBILL_NO, messageBody, digest, map);
        }
        else if(PubApiObjectConstants.WAYBILL_ARB_QUERY_BY_WAYBILL_NO.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("wayBillNo", String.valueOf(map.get("wayBillNo")));
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.WAYBILL_ARB_QUERY_BY_WAYBILL_NO, messageBody, digest, map);
        }
        else if(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_WAYBILL_NO.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("wayBillNo", String.valueOf(map.get("wayBillNo")));
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_WAYBILL_NO, messageBody, digest, map);
        }
        else if (PubApiObjectConstants.WAYBILL_ARB_QUERY_BY_COMPLAINT_NUM.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("arbitrationNo", String.valueOf(map.get("arbitrationNo")));
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.WAYBILL_ARB_QUERY_BY_COMPLAINT_NUM, messageBody, digest, map);
        }
        else if(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_ABNORMAL_CODE.equals(interfaceConstants)) {
            Map<String, Object> map_sort = new TreeMap<>();
            map_sort.put("abnormalCode", String.valueOf(map.get("abnormalCode")));
            String messageBody = SecurityUtils.md5(JSON.toJSONString(map_sort), "utf-8");
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_ABNORMAL_CODE, messageBody, digest, map);
        }else if(PubApiObjectConstants.SYSTEM_ALL_COMPANY.equals(interfaceConstants)) {
            JSONObject object = new JSONObject();
            String messageBody = SecurityUtils.md5(object.toJSONString(), null);
            String digest =  generateDigest(messageBody);
            json_object = convoterObjectByConstans(PubApiObjectConstants.SYSTEM_ALL_COMPANY, messageBody, digest, map);
        }
        return json_object;
    }


    private static String convoterObjectByConstans(String constans, String messageBody, String digest, Map map) {
        String result = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String srt_Date = sdf.format(new Date());
        if(PubApiObjectConstants.WAYBILL_QUERY_BY_WAYBILL_NO.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            wayBillQueryParamsVo.setDigest(digest);
            callSystemVo.setWayBillNo(map.get("wayBillNo").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        else if(PubApiObjectConstants.ROUTE_QUERY_BY_WAYBILL_NO.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            wayBillQueryParamsVo.setDigest(digest);
            callSystemVo.setWayBillNo(map.get("wayBillNo").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }else if(PubApiObjectConstants.ROUTE_TIME_QUERY_BY_WAYBILL_NO.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            LineVo lineVo =new LineVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setDigest(digest);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            lineVo.setSourceZoneCode(String.valueOf(map.get("sourceZoneCode")));
            Date d1 = new Date(Long.valueOf(map.get("orderTime").toString()));
            lineVo.setOrderTime(d1);
            lineVo.setProductCode(String.valueOf(map.get("productCode")));
            lineVo.setDestZoneCode(String.valueOf(map.get("destZoneCode")));
            wayBillQueryParamsVo.setLineVo(lineVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }else if(PubApiObjectConstants.WAYBILL_CHANGE_QUERY_BY_WAYBILL_NO.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setDigest(digest);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            callSystemVo.setWaybillNoArray((Long[])map.get("waybillNoArray"));
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }else if(PubApiObjectConstants.USER_QUERY.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setDigest(digest);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            callSystemVo.setUserCode(map.get("userCode").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        else if(PubApiObjectConstants.NETWORK_QUERY.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setDigest(digest);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            callSystemVo.setDeptCode(map.get("deptCode").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        else if(PubApiObjectConstants.WAYBILL_RECORD_QUERY_BY_WAYBILL_NO.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            wayBillQueryParamsVo.setDigest(digest);
            callSystemVo.setWayBillNo(map.get("wayBillNo").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        else if(PubApiObjectConstants.WAYBILL_SIGN_QUERY_BY_WAYBILL_NO.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            wayBillQueryParamsVo.setDigest(digest);
            callSystemVo.setWayBillNo(map.get("wayBillNo").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        else if(PubApiObjectConstants.WAYBILL_ARB_QUERY_BY_WAYBILL_NO.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            wayBillQueryParamsVo.setDigest(digest);
            callSystemVo.setWayBillNo(map.get("wayBillNo").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        else if(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_WAYBILL_NO.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            wayBillQueryParamsVo.setDigest(digest);
            callSystemVo.setWayBillNo(map.get("wayBillNo").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        else if(PubApiObjectConstants.WAYBILL_ARB_QUERY_BY_COMPLAINT_NUM.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            wayBillQueryParamsVo.setDigest(digest);
            callSystemVo.setArbitrationNo(map.get("arbitrationNo").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        else if(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_ABNORMAL_CODE.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            wayBillQueryParamsVo.setDigest(digest);
            callSystemVo.setAbnormalCode(map.get("abnormalCode").toString());
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        else if(PubApiObjectConstants.SYSTEM_ALL_COMPANY.equals(constans)) {
            WayBillQueryParamsVo wayBillQueryParamsVo = new WayBillQueryParamsVo();
            CallSystemVo callSystemVo = new CallSystemVo();
            wayBillQueryParamsVo.setAccessKey(asskey);
            wayBillQueryParamsVo.setCompCode(comcode);
            wayBillQueryParamsVo.setMessageBody(messageBody);
            wayBillQueryParamsVo.setSecretKey(seckey);
            wayBillQueryParamsVo.setTimestamp(srt_Date);
            wayBillQueryParamsVo.setVersion(version);
            wayBillQueryParamsVo.setDigest(digest);
            wayBillQueryParamsVo.setCallSystemVo(callSystemVo);
            result = JSON.toJSONString(wayBillQueryParamsVo);
        }
        return result;
    }

    private static String convoterObject(Object obj, String messageBody, String digest, Map map) {
        String result = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String srt_Date = sdf.format(new Date());
        if(obj instanceof OrderQueryParam) {
            OrderQueryParam orderQueryParam = (OrderQueryParam)obj;
            orderQueryParam.setAccessKey(asskey);
            orderQueryParam.setCompCode(comcode);
            orderQueryParam.setMessageBody(messageBody);
            orderQueryParam.setSecretKey(seckey);
            orderQueryParam.setTimestamp(srt_Date);
            orderQueryParam.setVersion(version);
            orderQueryParam.setDigest(digest);
            orderQueryParam.setPhone(map.get("phone").toString());
            orderQueryParam.setPageNum(Integer.valueOf(map.get("pageNum").toString()));
            result = JSON.toJSONString(orderQueryParam);
        }else if(obj instanceof OrderPostParamsVo) {
            OrderPostParamsVo orderPostParamsVo = (OrderPostParamsVo)obj;
            orderPostParamsVo.setAccessKey(asskey);
            orderPostParamsVo.setCompCode(comcode);
            orderPostParamsVo.setMessageBody(messageBody);
            orderPostParamsVo.setSecretKey(seckey);
            orderPostParamsVo.setTimestamp(srt_Date);
            orderPostParamsVo.setVersion(version);
            orderPostParamsVo.setDigest(digest);
            orderPostParamsVo.setOrderSource(map.get("orderSource").toString());
            orderPostParamsVo.setOrderVo((OrderVo)map.get("orderVo"));
            result = JSON.toJSONString(orderPostParamsVo);
        }else if(obj instanceof CustomerQueryVo) {
            CustomerQueryVo customerQueryVo = (CustomerQueryVo)obj;
            customerQueryVo.setAccessKey(asskey);
            customerQueryVo.setCompCode(comcode);
            customerQueryVo.setMessageBody(messageBody);
            customerQueryVo.setSecretKey(seckey);
            customerQueryVo.setTimestamp(srt_Date);
            customerQueryVo.setVersion(version);
            customerQueryVo.setDigest(digest);
            customerQueryVo.setPhoneNumber(map.get("phoneNumber").toString().trim());
            result = JSON.toJSONString(customerQueryVo);
        }else if(obj instanceof WaybillParam) {
            WaybillParam waybillParam =(WaybillParam)obj;
            waybillParam.setAccessKey(asskey);
            waybillParam.setCompCode(comcode);
            waybillParam.setDigest(digest);
            waybillParam.setMessageBody(messageBody);
            waybillParam.setSecretKey(seckey);
            waybillParam.setTimestamp(srt_Date);
            waybillParam.setVersion(version);
            waybillParam.setPhone(map.get("phone").toString());
            result = JSON.toJSONString(waybillParam);
        }else if(obj instanceof MsgCRMParam) {
            MsgCRMParam msgCRMParam = (MsgCRMParam)obj;
            msgCRMParam.setAccessKey(asskey);
            msgCRMParam.setCompCode(comcode);
            msgCRMParam.setDigest(digest);
            msgCRMParam.setMessageBody(messageBody);
            msgCRMParam.setSecretKey(seckey);
            msgCRMParam.setTimestamp(srt_Date);
            msgCRMParam.setVersion(version);
            msgCRMParam.setMobile(map.get("mobile").toString());
            msgCRMParam.setContent(map.get("content").toString());
            result = JSON.toJSONString(msgCRMParam);
        }
        return result;
    }
    private static String generateDigest(String messageBody) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String srt_Date = sdf.format(new Date());
        Map<String, String> paramsMap = new TreeMap<>();
        paramsMap.put("accessKey", asskey);
        paramsMap.put("compCode", comcode);
        paramsMap.put("messageBody", messageBody);
        paramsMap.put("secretKey", seckey);
        paramsMap.put("timestamp", srt_Date);
        paramsMap.put("version", version);
        JSONObject obj = new JSONObject();
        String digest = SecurityUtils.md5(obj.toJSONString(paramsMap), "utf-8");
        return digest;
    }

}
